package com.example.dryyzx.dao;

import com.example.dryyzx.entity.NursingContent;
import com.example.dryyzx.entity.NursingLevel;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface NursingContentMapper {
    @Delete({
        "delete from nursing_content",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into nursing_content (id, name, ",
        "price, remarks, ",
        "value_added_services, enable)",
        "values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{price,jdbcType=INTEGER}, #{remarks,jdbcType=VARCHAR}, ",
        "#{valueAddedServices,jdbcType=BIT}, #{enable,jdbcType=BIT})"
    })
    int insert(NursingContent record);

    @InsertProvider(type=NursingContentSqlProvider.class, method="insertSelective")
    int insertSelective(NursingContent record);

    @Select({
        "select",
        "id, name, price, remarks, value_added_services, enable",
        "from nursing_content",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="price", property="price", jdbcType=JdbcType.INTEGER),
        @Result(column="remarks", property="remarks", jdbcType=JdbcType.VARCHAR),
        @Result(column="value_added_services", property="valueAddedServices", jdbcType=JdbcType.BIT),
        @Result(column="enable", property="enable", jdbcType=JdbcType.BIT)
    })
    NursingContent selectByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, name, price, remarks, value_added_services, enable",
            "from nursing_content",
            "where name = #{name,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="price", property="price", jdbcType=JdbcType.INTEGER),
            @Result(column="remarks", property="remarks", jdbcType=JdbcType.VARCHAR),
            @Result(column="value_added_services", property="valueAddedServices", jdbcType=JdbcType.BIT),
            @Result(column="enable", property="enable", jdbcType=JdbcType.BIT)
    })
    NursingContent selectByName(String name);

    @Select({
            "select",
            "name",
            "from nursing_content",
            "where enable = 1"
    })
    @Results({
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR)
    })
    List<String> getContentNames();

    @Select({
            "select",
            "count(*)",
            "from nursing_content",
    })
    int countContent();

    @Select({
            "select",
            "id, name, price, remarks, value_added_services, enable",
            "from nursing_content",
            "limit #{arg0,jdbcType=INTEGER} offset #{arg1,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="price", property="price", jdbcType=JdbcType.INTEGER),
            @Result(column="remarks", property="remarks", jdbcType=JdbcType.VARCHAR),
            @Result(column="value_added_services", property="valueAddedServices", jdbcType=JdbcType.BIT),
            @Result(column="enable", property="enable", jdbcType=JdbcType.BIT)
    })
    List<NursingContent> selectByLimitAndOffset(Integer arg0, Integer arg1);

    @Select({
            "select",
            "id, name, price, remarks, value_added_services, enable",
            "from nursing_content",
            "where name like concat('%',#{name,jdbcType=VARCHAR},'%')",
            "limit #{arg0,jdbcType=INTEGER} offset #{arg1,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="price", property="price", jdbcType=JdbcType.INTEGER),
            @Result(column="remarks", property="remarks", jdbcType=JdbcType.VARCHAR),
            @Result(column="value_added_services", property="valueAddedServices", jdbcType=JdbcType.BIT),
            @Result(column="enable", property="enable", jdbcType=JdbcType.BIT)
    })
    List<NursingContent> selectNameByLimitAndOffset(Integer arg0, Integer arg1,String name);

    @Select({
            "select",
            "name",
            "from nursing_content",
            "where enable = 1"
    })
    @Results({
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR)
    })
    String getContentName();

    @Select({
            "select",
            "count(*)",
            "from nursing_content",
            "where name like concat('%',#{name,jdbcType=VARCHAR},'%')"
    })
    int countByName(String name);

    @UpdateProvider(type=NursingContentSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(NursingContent record);

    @Update({
        "update nursing_content",
        "set name = #{name,jdbcType=VARCHAR},",
          "price = #{price,jdbcType=INTEGER},",
          "remarks = #{remarks,jdbcType=VARCHAR},",
          "value_added_services = #{valueAddedServices,jdbcType=BIT},",
          "enable = #{enable,jdbcType=BIT}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(NursingContent record);
}